package controller

import (
	"GoAdmin/common"
	"GoAdmin/models"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"strconv"
	"xorm.io/builder"
)

func UserLog(c *gin.Context) {
	page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
	pageSize, _ := strconv.Atoi(c.DefaultQuery("pageSize", "15"))
	offset := (page - 1) * pageSize
	user, _ := common.GetCtxUser(c)
	filter := builder.NewCond()
	if user.Type != "0" {
		filter = filter.And(builder.Eq{"o.user_id": user.Id})
	}
	list, count, err := new(models.OaLog).UserLogList(filter, pageSize, offset)
	if err != nil {
		log.Println(err)
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "ok", "data": gin.H{"list": list, "count": count}})
	return
}

func SchoolConfig(c *gin.Context) {
	var (
		schoolId string
	)
	if schoolId = c.Query("school_id"); schoolId == "" {
		c.JSON(http.StatusOK, gin.H{"code": 201, "msg": "信息错误"})
		return
	}
	ok, list, err := new(models.SchoolNewconfig).GetSchoolConfig(schoolId)
	if !ok {
		c.JSON(http.StatusOK, gin.H{"code": 201, "msg": "配置信息错误"})
		return
	} else if err != nil {
		c.JSON(http.StatusOK, gin.H{"code": 201, "msg": "查询信息错误"})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "ok", "data": gin.H{"list": list}})
	return
}

func SetConfig(c *gin.Context) {

}
